<!DOCTYPE html>
<html>
<head>
    <meta charset=utf-8"UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>用户</title>
    <link rel="stylesheet" href="__PUBLIC__/mui.min.css"/>
    <link rel="stylesheet" href="__PUBLIC__/iconfont.css" />
    <link rel="stylesheet" href="__PUBLIC__/app.css"/>
</head>
<body>
<header class="mui-bar mui-bar-nav user">
    <div class="user-head">
        <div class="user-img"><img src="__PUBLIC__/jd/user-icon.png" id="img" /></div>
        <div class="user-name" id="username">



        </div>
    </div>
</header>
<div class="mui-content user-content">
    <ul class="mui-table-view">
        <!-- <li class="mui-table-view-cell">
            <a class="mui-navigate-right" href="#" onclick="pageJumpIsLogin('/index/index/message')">
                <span class="iconfont icon-xiaoxi iconcolor"></span>
                   <span class="user-title">我的消息</span>
            </a>
        </li> -->
        <!--<li class="mui-table-view-cell">-->
            <!--<a class="mui-navigate-right" href="#" onclick="isLogin('/index/user/apply.html')">-->
                <!--<span class="iconfont icon-wodeshenqing iconcolor"></span>-->
                <!--<span class="user-title">我的申请</span>-->
            <!--</a>-->
        <!--</li>-->
        <!--<li class="mui-table-view-cell">-->
            <!--<a class="mui-navigate-right" href="#" onclick="isLogin('/index/user/data.html')">-->
                <!--<span class="iconfont icon-gerenziliao iconweixin iconcolor"></span>-->
                <!--<span class="user-title">个人资料</span>-->
            <!--</a>-->
        <!--</li>-->
        <!--<li class="mui-table-view-cell">-->
            <!--<a class="mui-navigate-right" href="#">-->
                <!--<span class="iconfont icon-weixin-copy iconcolor"></span>-->
                <!--<span class="user-title">微信咨询</span>-->
            <!--</a>-->
        <!--</li>-->
        <li class="mui-table-view-cell">
            <a class="mui-navigate-right" href="#" onclick="pageJump('/index/system/setup')">
                <span class="iconfont icon-shezhi iconcolor"></span>
                <span class="user-title">设置</span>
            </a>
        </li>
    </ul>
</div>
<nav class="mui-bar mui-bar-tab">
    <a class="tab-item" onclick="pageJump('/index/index/home.html', false)">
        <div class="iconfont icon-zhuye"></div>
        <span class="mui-tab-label">主页</span>
    </a>
    <a class="tab-item" onclick="pageJump('/index/index/supermarket.html', true)">
        <div class="iconfont icon-zhuyecanting"></div>
        <span class="mui-tab-label">产品超市</span>
    </a>
    <a class="tab-item mui-active">
        <div class="iconfont icon-user"></div>
        <span class="mui-tab-label">个人中心</span>
    </a>
</nav>
<script src="__PUBLIC__/jquery.min.js"></script>
<script>
    //顶部
    $('.mui-bar').css('backgroundColor', "#f15e70");
    $('.user-name a, #username').css('color', "#ffffff");
    // 底部
    $('.mui-bar-tab').css('backgroundColor', "#f15e70");
    $('.mui-bar-tab .tab-item').css('color', "#ffffff");
    $('.mui-bar-tab .tab-item.mui-active').css({'backgroundColor':"#ffffff",'color':"#f15e70"});
    //文字
    $('.iconcolor, .user-title').css('color', "#f15e70");
</script>
<script src="__PUBLIC__/mui.min.js"></script>
<script type="text/javascript">
    var isUser = localStorage.getItem("user");
    if(isUser){
        var userJson = JSON.parse(isUser);
        if(userJson["nickname"] == "''"){
            $('#username').html('未填写');
        } else {
            $('#username').html(userJson["nickname"]);
        }
        if(userJson["icon_url"] == "''"){
            $('#img').attr("src", '/public/static/index/images/user-icon.png');
        } else {
            $('#img').attr("src", userJson["icon_url"]);
        }
    }
    function pageJump(url, cate_id){
        if(cate_id){
            window.location.href = url+'?cate_id=' + localStorage.getItem("cate_id");
        } else {
            window.location.href = url;
        }
    }
   function setAvatar(){
        if(isUser){
            window.location.href = "/index/system/avatar.html";
        }
    }
    $("#username").click(function(){
        if(isUser){
            var btnArray = ['取消', '确定'];
            mui.prompt('请输入新的昵称：', '昵称', '提示', btnArray, function(e) {
                if (e.index == 1) {
                    var _self = this;
                    $.post('/index/user/setNickname',{"nickname": e.value,"id": userJson["id"]},function(res){
                        var jsonp = JSON.parse(res);
                        document.activeElement.blur();
                        if(jsonp["valid"]){
                            mui.toast(jsonp["msg"], 1500);
                            _self.getUser();
                        }
                    });
                }
            })
        }
    });
    function isLogin(url){
        if(!isUser){
            mui.toast("您还没登录，请登录");
            setTimeout(function(){
                window.location.href = "/index/apply/login.html";
            }, 2000);
            return;
        } else {
            window.location.href = url;
        }
    }

    if ( !isUser ){
        html = '<a href="/index/apply/login.html">　立即登录</a>';
    }else{

        html = '　'+isUser;
    }

    $('#username').html(html);

</script>
</body>
</html>